from main import db


def rent_query_by_day(content, day):
    # 先判断该日期有没有租客
    if not db.select_day(day=int(day), remove_yizu=False):
        content = "该日期没有租客"
    else:
        data = db.select_day(day=int(day))
        # 然后查询该日期未收租的租客，如果没有未收租，则回复所有房租已收
        if not data:
            content = "该日期所有房租已收"
        else:
            for row in data:
                # 有些没有加好的数字被excel定义为int类型，需要转换一下
                row[7] = str(row[7]) + " " * (7 - len(str(row[7]))) * 2  # 一个数字字符宽度等于两个半角空格
                row[0] = row[0] + "\u3000" * (3 - len(row[0]))  # 一个汉字宽度等于一个全角空格
                row[4] = str(row[4]) + " " * (9 - len(str(row[4])))
                content = content + f"{row[7]}  {row[0]}  {row[4]}  " \
                                    f"<a href=\"http://a.efrey.top/wx/rent?address={row[7].strip()}&name={row[0].strip()}&day={row[2]}\">收租</a>\n"
                return content